import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;

public class SimpleApp{	
	public static void main(String[] args) {
		//SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss"); 
		try {
			
			//Minus two times
			/*
			String time1 = "10:20:00";
			String time2 = "10:19:00";
			Date date1 = sdf.parse(time1);
			Date date2 = sdf.parse(time2);
			
			//Calendar calendar1 = java.util.GregorianCalendar.getInstance();
			//calendar1.setTime(date1);
			//Calendar calendar2 =java.util.GregorianCalendar.getInstance();
			//calendar2.setTime(date2);
			System.out.println("date1:" + date1.getTime());
			System.out.println("date2:" + date2.getTime());
			//System.out.println("Result:" + calendar1.compareTo(calendar2));
			long result = (date1.getTime() - date2.getTime())/1000;//Ans is in seconds
			System.out.println("Result:" + result);
			*/
			
			//Get last modified time
			/*
			File f = new File("test.txt");
			if(f.exists()){
				long lastModified = f.lastModified();
				System.out.println("Last Modified:" + lastModified);
				Date date = new Date(lastModified);
				System.out.println("Date Modified: " + date.toString());
				Calendar calendar = java.util.GregorianCalendar.getInstance();
				calendar.setTime(date);
				System.out.println(calendar.get(Calendar.HOUR_OF_DAY)+":"+calendar.get(Calendar.MINUTE)+":"+calendar.get(Calendar.SECOND));
				//System.out.println(date.getHours()+":"+date.getMinutes()+":"+date.getSeconds());
			}*/
			
			//Message split
			/*
			String str2 = "A|bunch|of|stars";
			String[] starwords = str2.split("\\|");
			System.out.println("starwords.size: " + starwords.length);
			for (int i=0; i < starwords.length; i++) {
			  System.out.println (starwords[i]);
			}
			*/
			
			//Get subset of String
			/*String contents = "abcde";
			String result = new String(contents.getBytes(),3,5);
			System.out.println("Result:" + result);
			*/
			
			
			/*Operations operation = new Operations();
			//operation.randomRead("test.txt",3,10);
			operation.readFile("test.txt");
			System.out.println("Read Result:" + operation.getContent());
			
			//operation.randomWrite("test.txt",2,"TEST");
			operation.appendWrite("test.txt","123456");
			operation.readFile("test.txt");
			System.out.println("Write Result:" + operation.getContent());*/
			
			//Inform after 5 seconds have passed
			/*
			System.out.println("About to schedule task.");
			new ReminderBeep(5);
			System.out.println("Task scheduled.");
			*/
			
			MyThread thread1 = new MyThread();
			thread1.seconds = 5;
			thread1.threadid = 1;
			System.out.println("Task1.");
			thread1.start();
			
			MyThread thread2 = new MyThread();
			thread2.seconds = 2;
			thread2.threadid = 2;
			System.out.println("Task2.");
			thread2.start();
			
		}
		catch ( Exception e){
			e.printStackTrace();
		}
	}
	
	static class MyThread extends Thread
	{
	   Timer timer;
	   int seconds;
	   int threadid;
	   
	   public void run ()
	   {
		System.out.println("Thread Id="+threadid);
		System.out.println("Seconds="+seconds);
		timer = new Timer();
		RemindTask task = new RemindTask();
		task.id = threadid;
		timer.schedule(task, seconds * 1000);
		System.out.println("Task scheduled.");
	   }
	   
	   class RemindTask extends TimerTask {
			int id;
			public void run() {
				System.out.println("ID: "+id+" Time's up!");
				timer.cancel(); //Not necessary because we call System.exit
				//System.exit(0); //Stops the AWT thread (and everything else)
			}
		}
	}

}


/*
class ReminderBeep {
	Timer timer;

	ReminderBeep(int seconds) {
		timer = new Timer();
		timer.schedule(new RemindTask(), seconds * 1000);
	}
	
	class RemindTask extends TimerTask {
		public void run() {
			System.out.println("Time's up!");
			timer.cancel(); //Not necessary because we call System.exit
			//System.exit(0); //Stops the AWT thread (and everything else)
		}
	}
}*/

/**
 * Simple demo that uses java.util.Timer to schedule a task to execute once 5
 * seconds have passed.
 */
/*
public class ReminderBeep {
  Toolkit toolkit;

  Timer timer;

  public ReminderBeep(int seconds) {
    toolkit = Toolkit.getDefaultToolkit();
    timer = new Timer();
    timer.schedule(new RemindTask(), seconds * 1000);
  }

  class RemindTask extends TimerTask {
    public void run() {
      System.out.println("Time's up!");
      toolkit.beep();
      //timer.cancel(); //Not necessary because we call System.exit
      System.exit(0); //Stops the AWT thread (and everything else)
    }
  }

  public static void main(String args[]) {
    System.out.println("About to schedule task.");
    new ReminderBeep(5);
    System.out.println("Task scheduled.");
  }
}*/